<#include "/layout/layout.ftl">
<#import "/layout/macro.ftl" as macro>
<#assign css>

<link rel="stylesheet" href="/assets/vendor/fileinput/css/fileinput.min.css">
</#assign>
<#assign js>
	<script src="/assets/vendor/fileinput/js/fileinput.min.js"></script>
    <script src="/assets/vendor/fileinput/js/locales/zh.js"></script>

<script>
    $(function(){

        $("#start_img").fileinput({
            language: 'zh', //设置语言
            uploadUrl: "/upload/uploadImg", //上传的地址
            allowedFileExtensions: ['jpg', 'png', 'gif', 'jpeg'],//接收的文件后缀
            showUpload: true, //是否显示上传按钮
            showCaption: false,//是否显示标题
            showRemove: false, // 是否显示移除按钮
            maxFileCount: 1,//上传图片最大数量
            browseClass: "btn btn-primary", //按钮样式
            previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
                <#if imgs?? >
                <#list imgs as img>
                initialPreview: [
                    "<img src='/${img}' class='file-preview-image kv-preview-data'>"
                ],
                </#list>
                </#if>
        });



        $("#start_img").on("fileuploaded", function (event, data, previewId, index) {
            debugger;
            var urls = $("#imgUrl").val();
            $("#imgUrl").val(data.response.data);
            $.ajax({
                type: "POST",
                dataType: "json",
                url: "/bootstrapimg/edit",
                data: $(".form-edit").serialize(),
                success: function(res){
                    if(res.code=='0'){
                        layer.msg(res.message, {time: 2000
                        }, function(){
                            location.href="/bootstrapimg/index";
                        });
                    }else{
                        layer.msg(res.message);
                    }


                },
                error:function(){
                    layer.msg("shibai ");
                }
            });



        });

        $('#start_img').on('filesuccessremove', function(event, id, index) {
            $("#imgUrl").val('');

        });



    });


</script>
</#assign>
<@layout title="启动页/引导页图片设置" active="bootstrapimg">
<!-- Content Header (Page header) -->
<section class="content-header">
    <h1>
        启动页/引导页图片设置
        <small>编辑</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="/"><i class="fa fa-home"></i> 管理后台</a></li>
        <li class="active"><i class="fa fa-edit"></i> 启动页/引导页图片设置</li>
    </ol>
</section>
<!-- Main content -->
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <!-- Default box -->
            <div class="box  box-primary">
                <form class="form-horizontal form-edit" method="post" action="/bootstrapimg/edit">
                    <div class="box-body">
                        <input type="hidden" id="id" name="id" value="${bootstrapImg.id!}">
                        <input type="hidden" id="isAdd" name="isAdd" value="${isAdd?string('true','false')}">
                        <input type="hidden" id="imgUrl" name="imgUrl" value="${bootstrapImg.imgUrl!}">

                        <div class="form-group">
                            <label class="col-sm-2 control-label">图片类型：</label>
                            <div class="col-sm-10">
                                <select class="form-control" name="type" id="type" required disabled>
                                    <option value="">请选择图片类型</option>
                                    <option value="0" <#if bootstrapImg.type??&&bootstrapImg.type==0 >selected</#if>>启动页</option>
                                    <option value="1" <#if bootstrapImg.type??&&bootstrapImg.type==1 >selected</#if>>引导页</option>
                                </select>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">上传图片：</label>
                            <div class="col-sm-10">
                                <input type="file" id="start_img" name="file" >
                            </div>
                        </div>
                    </div>
                    <div class="box-footer">
                        <button type="button" class="btn btn-default btn-back">返回</button>
                        <#--<button type="button" class="btn btn-primary pull-right btn-submit">提交</button>-->
                    </div>
                </form>
            </div>
            <!-- /.box -->
        </div>
    </div>
</section>
<!-- /.content -->
</@layout>